using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace FiveChess
{

    public enum ChessmanType
    {
        Undefined,
        Black,
        White
    }
    /// <summary>
    /// Represents a chessman
    /// </summary>
    class Chessman:IDrawScreen 
    {

        private ChessmanType chessType;
        private Point chessPoint;

        private int stepNumber=-1;

        private Image chessmanImage;

        private ImageAttributes attr = new ImageAttributes();      

        public Chessman()
        { 
            chessType = ChessmanType.Undefined;
            chessmanImage = null;
            chessPoint.X = -1;
            chessPoint.Y = -1;
        }

        public Chessman(ChessmanType chessmanType)
        {
            this.chessType = chessmanType;
            switch (chessType)
            {
                case ChessmanType.Undefined :
                    break;
                case ChessmanType.Black :
                    chessmanImage = Image.FromFile("images/Black.bmp");
                    break;
                case ChessmanType.White :
                    chessmanImage=Image.FromFile("images/White.bmp");
                    break;            
            }
        }

        public Chessman(Point pPoint)
        {
            this.chessPoint = pPoint;
        }

        public Chessman(ChessmanType chessmanType, Point pPoint)
        {
            this.chessPoint = pPoint;
            this.chessType = chessmanType;
            switch (chessType)
            {
                case ChessmanType.Undefined:
                    break;
                case ChessmanType.Black:
                    chessmanImage = Image.FromFile("images/Black.bmp");
                    break;
                case ChessmanType.White:
                    chessmanImage = Image.FromFile("images/White.bmp");
                    break;
            }
        }

        public Image ChessManImage
        {
            get
            {
                // Returns the brickImage attribute.
                return chessmanImage;
            }
            set
            {
                // Sets the brickImage attribute to the value.
                chessmanImage = value;
            }
        }

        public Point  ChessPoint
        {
            get
            {
                return chessPoint ;
            }

            set
            {
                chessPoint  = value;
            }
        }

        public int StepNumber
        {
            get
            {
                return stepNumber;
            }

            set
            {
                stepNumber = value;
            }
        }

        public ChessmanType ChessType
        {
            get
            {
                return chessType ;
            }

        }
        void  IDrawScreen.Draw(Graphics drawingSurface)
        {
            if (chessmanImage != null)
            {
                Rectangle rect = new Rectangle(this.chessPoint.X * PublicConfigParameter.ChessmanImageLen + PublicConfigParameter.ChessmanImageLen / 2, this.chessPoint.Y * PublicConfigParameter.ChessmanImageLen + PublicConfigParameter.ChessmanImageLen / 2, PublicConfigParameter.ChessmanImageLen, PublicConfigParameter.ChessmanImageLen);
                attr.SetColorKey(Color.Yellow, Color.White);
                drawingSurface.DrawImage(this.ChessManImage, rect, 0, 0, PublicConfigParameter.ChessmanImageLen, PublicConfigParameter.ChessmanImageLen, GraphicsUnit.Pixel, attr);
            }
        }
    }


}
